package com.pan.alg.niuke.link;

import java.util.ArrayList;
import java.util.List;

public class LinkFindFirstCommonNode {

    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {

        List<ListNode> listNode = new ArrayList<>();
        while(pHead1!=null){
            listNode.add(pHead1);
            pHead1=pHead1.next;
        }
        ListNode common =null;
        while(pHead2!=null){
            if(listNode.contains(pHead2)){
                common= pHead2;
                break;
            }
            pHead2=pHead2.next;
        }

        return common;
    }
}
